import { queryPerson, addPerson,removePerson,updatePerson,queryOrgUserTree,queryDIYOrgTree} from '@/services/bnsConfig/editOrg';

export default {
  namespace: 'editOrg',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },

    queryForm:{},

  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryPerson, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addPerson, payload);
      yield put({
        type: 'saveadd',
        payload: response,
      });
      if (callback) callback(response);
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removePerson, payload);
      yield put({
        type: 'saveremove',
        payload: response,
      });
      if (callback) callback(response);
    },
    *update({ payload, callback }, { call, put }) {
      const response = yield call(updatePerson, payload);
      yield put({
        type: 'saveupdate',
        payload: response,
      });
      if (callback) callback(response);
    },
    *orgUserTree({ payload, callback }, { call, put }) {
      const response = yield call(queryOrgUserTree, payload);
      yield put({
        type: 'saveorgUserTree',
        payload: response,
      });
      if (callback) callback(response);
    },
    * diyOrgTree({payload, callback}, {call, put}) {
      const response = yield call(queryDIYOrgTree, payload);
      yield put({
        type: 'diyList',
        payload: response,
      });
      if (callback) callback(response);
    },
  },

  reducers: {
    save(state, action) {
      if(action.payload.rescode == 200){
        return {
        ...state,
        data: action.payload.data,
        };
      }else{        
        alert(action.payload.msg)
        return {
        ...state,
        data: [],
        };
      }
    },
  },
};
